//Begin #online div ajax
$(document).ready(function(){
	OnlineUser();
});
function OnlineUser(){
$(document).ready(function(){
	var target = $("#online");
	var wbname = $("#wbname_input");
			$.ajax({
				type: "POST", url: '../module/member/memberonlinexxx.php', 
				data: "wbname="+wbname.val(),
				complete: function(data){
						target.html(data.responseText);
				}
			});
	});
}
setInterval( "OnlineUser()", 300000 );
//End #online div ajax

function addscore(uid,uidgift,boardname){
	var name;
$(document).ready(function(){
			$.ajax({
				type: "POST", url: '../module/member/addscore.php', 
				data: "uid="+uid+"&uidgift="+uidgift+"&boardname="+boardname,
				complete: function(data){
				alert(data.responseText);
				}
			});
	});
}


//Begin login ajax
$(document).ready(function(){
	var username = $("#username");
	var password = $("#password");
	remember = $('#remember2');
	var target = $("#mySpan");
	
	function checkForm(){
		if(username.val()==""){ 
			target.html("<font color=red>กรุณากรอกชื่อผู้ใช้</font>"); 
			username.focus();
			target.show('slow');
			return false; 
		}
			if(password.val()==""){ 
				target.html("<font color=red>กรุณากรอกรหัสผ่าน</font>"); 
				password.focus();
				target.show('slow');
				return false; 
			}
			if(username.attr("value") && password.attr("value"))
			return true;
		else
			return false;
	}
$("#loginform").submit(function(){
		if(checkForm()){
			target.show('slow');

			$.ajax({
				type: "POST", url: '../module/member/logincheck.php', 
				data: "tUsername="+username.val()+"&tPassword="+password.val()+"&logintype=username&remember1="+remember.attr('checked'),
				complete: function(data){
					if(data.responseText == 'Y'){
					$("#login").html("<center><img src='../images/loading.gif'><br><br>เข้าสู่ระบบเรียบร้อยแล้ว<br><br><center>");
					setTimeout('window.location.href=""', 2000)
					//	target.html(data.responseText);
					}
						else
						target.html(data.responseText);
				}
			});
		}
		else 
		return false;
	});
});

$(document).ready(function(){
	var usrlogin = $("#usrlogin");
	var psslogin = $("#psslogin");
	remember2 = $('#remember1');
	var target = $("#sta_login");
	var logintype = $("#fastloginfield");
	
	function checkForm2(){
		if(usrlogin.val()==""){ 
			//alert("กรุณากรอกชื่อผู้ใช้"); 
			$.msgbox("<font color='red' style='font-size:25px;'>กรุณากรอกชื่อผู้ใช้</font>");
			//usrlogin.focus();
			return false; 
		}
			if(psslogin.val()==""){ 
				//alert("กรุณากรอกรหัสผ่าน"); 
				$.msgbox("<font color='red' style='font-size:25px;'>กรุณากรอกรหัสผ่าน</font>");
				//psslogin.focus();
				return false; 
			}
			if(usrlogin.attr("value") && psslogin.attr("value"))
			return true;
		else
			return false;
	}
$("#fastlogin").submit(function(){
		if(checkForm2()){

			$.ajax({
				type: "POST", url: '../module/member/logincheck.php', 
				data: "tUsername="+usrlogin.val()+"&tPassword="+psslogin.val()+"&logintype="+logintype.val()+"&remember2="+remember2.attr('checked'),
				complete: function(data){
					if(data.responseText == 'Y'){
					target.html("<img width='22px' height='22px' src='../images/loading.gif' style='vertical-align:middle;'><font style='color:green;'>เข้าสู่ระบบเรียบร้อยแล้ว</font>");
					setTimeout('window.location.href=""', 2000)
					//	target.html(data.responseText);
					}
						else
						$.msgbox("<font color='red' style='font-size:20px;'>"+data.responseText+"</font>");
						//target.html(data.responseText);
				}
			});
		}
		else 
		return false;
	});
});
//End login ajax

//Begin Logout ajax
function logout(){
	$.msgbox("คุณต้องการออกจากระบบ?", {type: "confirm",buttons : [{type: "submit", value: "Yes"},{type: "submit", value: "No"}]}, 
	function(result) { 
	if(result=="Yes"){
	$(document).ready(function(){
			$.ajax({
				type: "POST", url: '../module/member/logout.php', 
				data: "",
				complete: function(data){
				$.cookie("login_id", null);
				setTimeout('window.location.href=""', 1000);
				}
			});
	});
	}else{
		
	}
	});
	


}
//End Logout ajax

//Begin change pass ajax
$(document).ready(function(){
	var old_password = $("#old_password");
	var new_password = $("#new_password");
	var renew_password = $("#renew_password");
	var target = $("#passSpan");
	
	function checkForm(){
		if(old_password.val()==""){ 
			target.html("<font color=red>กรุณากรอกรหัสผ่านเดิม</font>"); 
			target.show('slow');
			old_password.focus();
			return false; 
		}
			if(new_password.val()==""){ 
				target.html("<font color=red>กรุณากรอกรหัสผ่านใหม่</font>"); 
				target.show('slow');
				new_password.focus();
				return false; 
			}
			if(new_password.val().length < 5){ 
				target.html("<font color=red>รหัสผ่านจะต้องไม่ต่ำกว่า4ตัว</font>"); 
				target.show('slow');
				new_password.focus();
				return false; 
			}
				if(renew_password.val()==""){ 
					target.html("<font color=red>กรุณากรอกรหัสผ่านใหม่อีครั้ง</font>"); 
					target.show('slow');
					renew_password.focus();
					return false; 
				}
					if(renew_password.val()!=new_password.val()){ 
						target.html("<font color=red>รหัสผ่านใหม่ไม่ตรงกัน</font>"); 
						target.show('slow');
						renew_password.focus();
						return false; 
					}
						if(renew_password.val().length < 5){ 
						target.html("<font color=red>รหัสผ่านจะต้องไม่ต่ำกว่า4ตัว</font>"); 
						target.show('slow');
						renew_password.focus();
						return false; 
						}
			if(old_password.attr("value") && new_password.attr("value") && renew_password.attr("value"))
			return true;
		else
			return false;
	}
$("#editpassform").submit(function(){
		if(checkForm()){
			target.show('slow');
			$.ajax({
				type: "POST", url: '../module/member/changepasscheck.php', 
				data: "old_password="+old_password.val()+"&new_password="+new_password.val()+"&renew_password="+renew_password.val(),
				complete: function(data){
					if(data.responseText == 'Y'){
					$("#change_password").html("<center><img src='../images/loading.gif'><br><br>เปลี่ยนรหัสผ่านเรียบร้อยแล้ว<br><br><center>");
					setTimeout('window.location.href=""', 2000)
					//	target.html(data.responseText);
					}
						else
						target.html(data.responseText);
				}
			});
		}
		else 
		return false;
	});
});
//End change pass ajax
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
